package com.base.action;

import java.util.Date;
import java.util.List;

import com.base.service.CardTypeService;
import com.base.service.DepartmentService;
import com.base.service.DictService;
import com.base.service.FlowworkitemService;
import com.common.bean.Cardmaintype;
import com.common.bean.Datadict;
import com.common.bean.Department;
import com.common.bean.Flowworkitem;
import com.common.bean.Personnel;
import com.common.util.PagerModel;
import com.common.util.StringToken;
import com.core.ssh2.AbstractActionSupport;
import com.opensymphony.xwork2.Preparable;

public class FlowworkitemManagerAction extends AbstractActionSupport implements
		Preparable {
	private static final long serialVersionUID = 910883867641042778L;

	private FlowworkitemService flowworkitemService;
	
	private DictService dictService;
	
	private DepartmentService departmentService;
	
	private CardTypeService cardTypeService;
	
	private List<Datadict> datadictByReleasestatusnolist;
	
	private List<Datadict> datadictByFlaglist;
	
	private List<Department> departmentlist;
	
	private List<Cardmaintype> cardmaintypelist;
	
	private Flowworkitem flowworkitem;
	
	private	PagerModel pm;
	
	private long workflowno;
	
	@SuppressWarnings("unchecked")
	public void prepare() throws Exception {
		departmentlist = departmentService.findAllleafDepartment();
		cardmaintypelist = cardTypeService.findAllCardmaintype();
		datadictByFlaglist = dictService.findDictDetail(StringToken.DICT_FLOWFLAG);
		datadictByReleasestatusnolist = dictService.findDictDetail(StringToken.DICT_FLOWRELEASESTATUS);
	}	
	
	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}

	public String goAddFlowworkitem() throws Exception {
		return SUCCESS;
	}
	
	public String addFlowworkitem() throws Exception {
		Personnel personnel = (Personnel) getSession().get(StringToken.CURRENT_LOGIN);
		if(personnel == null) {
			throw new RuntimeException("no login!");
		}
		flowworkitem.setPersonnel(personnel);
		flowworkitem.setCreatedate(new Date());
		flowworkitem.setUpdatedate(new Date());
		flowworkitemService.addFlowworkitem(flowworkitem);
		return SUCCESS;
	}
	
	public String findAllFlowworkitem() throws Exception {
		pm = flowworkitemService.findFlowworkitemForPager();
		return SUCCESS;
	}
	
	public String findFlowworkitem() throws Exception {
		flowworkitem = flowworkitemService.findFlowworkitem(workflowno);
		return SUCCESS;
	}
	
	public String delFlowworkitem() throws Exception {
		flowworkitemService.removeFlowworkitem(workflowno);
		return SUCCESS;
	}
	
	public String getFlowworkitemForUpdate() throws Exception {
		flowworkitem = flowworkitemService.findFlowworkitem(workflowno);
		return SUCCESS;
	}
	
	public String updateFlowworkitem() throws Exception {
		Personnel personnel = (Personnel) getSession().get(StringToken.CURRENT_LOGIN);
		if(personnel == null) {
			throw new RuntimeException("no login!");
		}
		flowworkitem.setPersonnel(personnel);
		flowworkitem.setUpdatedate(new Date());
		flowworkitemService.updateFlowworkitem(flowworkitem);
		return SUCCESS;
	}

	/**
	 * @return the cardmaintypelist
	 */
	public List<Cardmaintype> getCardmaintypelist() {
		return cardmaintypelist;
	}

	/**
	 * @param cardmaintypelist the cardmaintypelist to set
	 */
	public void setCardmaintypelist(List<Cardmaintype> cardmaintypelist) {
		this.cardmaintypelist = cardmaintypelist;
	}

	/**
	 * @return the cardTypeService
	 */
	public CardTypeService getCardTypeService() {
		return cardTypeService;
	}

	/**
	 * @param cardTypeService the cardTypeService to set
	 */
	public void setCardTypeService(CardTypeService cardTypeService) {
		this.cardTypeService = cardTypeService;
	}

	/**
	 * @return the datadictByFlaglist
	 */
	public List<Datadict> getDatadictByFlaglist() {
		return datadictByFlaglist;
	}

	/**
	 * @param datadictByFlaglist the datadictByFlaglist to set
	 */
	public void setDatadictByFlaglist(List<Datadict> datadictByFlaglist) {
		this.datadictByFlaglist = datadictByFlaglist;
	}

	/**
	 * @return the datadictByReleasestatusnolist
	 */
	public List<Datadict> getDatadictByReleasestatusnolist() {
		return datadictByReleasestatusnolist;
	}

	/**
	 * @param datadictByReleasestatusnolist the datadictByReleasestatusnolist to set
	 */
	public void setDatadictByReleasestatusnolist(
			List<Datadict> datadictByReleasestatusnolist) {
		this.datadictByReleasestatusnolist = datadictByReleasestatusnolist;
	}

	/**
	 * @return the departmentlist
	 */
	public List<Department> getDepartmentlist() {
		return departmentlist;
	}

	/**
	 * @param departmentlist the departmentlist to set
	 */
	public void setDepartmentlist(List<Department> departmentlist) {
		this.departmentlist = departmentlist;
	}

	/**
	 * @return the departmentService
	 */
	public DepartmentService getDepartmentService() {
		return departmentService;
	}

	/**
	 * @param departmentService the departmentService to set
	 */
	public void setDepartmentService(DepartmentService departmentService) {
		this.departmentService = departmentService;
	}

	/**
	 * @return the dictService
	 */
	public DictService getDictService() {
		return dictService;
	}

	/**
	 * @param dictService the dictService to set
	 */
	public void setDictService(DictService dictService) {
		this.dictService = dictService;
	}

	/**
	 * @return the flowworkitem
	 */
	public Flowworkitem getFlowworkitem() {
		return flowworkitem;
	}

	/**
	 * @param flowworkitem the flowworkitem to set
	 */
	public void setFlowworkitem(Flowworkitem flowworkitem) {
		this.flowworkitem = flowworkitem;
	}

	/**
	 * @return the flowworkitemService
	 */
	public FlowworkitemService getFlowworkitemService() {
		return flowworkitemService;
	}

	/**
	 * @param flowworkitemService the flowworkitemService to set
	 */
	public void setFlowworkitemService(FlowworkitemService flowworkitemService) {
		this.flowworkitemService = flowworkitemService;
	}

	/**
	 * @return the pm
	 */
	public PagerModel getPm() {
		return pm;
	}

	/**
	 * @param pm the pm to set
	 */
	public void setPm(PagerModel pm) {
		this.pm = pm;
	}

	/**
	 * @return the workflowno
	 */
	public long getWorkflowno() {
		return workflowno;
	}

	/**
	 * @param workflowno the workflowno to set
	 */
	public void setWorkflowno(long workflowno) {
		this.workflowno = workflowno;
	}
	
	
}
